<?php

namespace app\admin\model;

use think\Db;
use app\admin\model\Common;
use think\Session;
use think\Validate;

class  Exwork extends Common
{
   //工作经历添加
   public function WriteExwork($param)
  {
    $info['work']=$param['work'];
    $info['preoccupation']=$param['preoccupation'];
    $info['start_time']=$param['start_time'];
    $info['end_time']=$param['end_time'];
    $info['train_id']=$param['train_id'];
    $info['status']=2;
    $info['status1']=2;
    $info['name']=$param['name'];
    $res=Db::table('oa_admin_exwork')
                   ->insert($info);
       if($res){
            return true;
       }else{
       	return false;
       }
  }

  //工作经历列表
  public function ListExwork($param)
  {
     $list=Db::table('oa_admin_exwork')
        ->where('train_id',$param['train_id'])
        ->field('id,work,preoccupation,start_time,end_time,status')
        ->select();
     return $list;
  }
  //工作经历修改
   public function ReviseExwork($param)
  {
     $id=$param['id'];
     $info['work']=$param['work'];
     $info['preoccupation']=$param['preoccupation'];
     $info['start_time']=$param['start_time'];
     $info['end_time']=$param['end_time'];
     $info['updata_time']=date('Y-m-d');
    $status=Db::table('oa_admin_exwork')
            ->where('id',$id)
            ->field('status')
            ->select();
         if($status[0]['status']=='2')
          {
            $info['status']=4; 
            $info['ps']='工作经历';
          }if($status[0]['status']=='3'){
          	$info['status']=1; 
          }if($status[0]['status']=='1'){
          	$info['status']=1;
          }
     $res= Db::table('oa_admin_exwork')
          ->where('id',$id)
          ->find();
     if($res){
         Db::table('oa_admin_exwork')
          ->where('id',$id)
          ->update([
            'work'=> $info['work'],
            'preoccupation'=>$info['preoccupation'],
            'start_time'=>$info['start_time'],
            'end_time'=>$info['end_time'],
            'status'=> $info['status'],
            'updata_time'=>$info['updata_time'],
            'ps'=>$info['ps'],
          ]);

           return true;
          }else{
          	return false;
          }
  }
  //工作经历删除
    public function DeleteExwork($param)
    {
    	$id=$param['id'];
    	$res= Db::table('oa_admin_exwork')
          ->where('id',$id)
          ->delete();
          if($res){
          	return true;
          }else{
          	return false;
          }
    }
}